package com.example.newproject_overseas.Screen

import android.os.Build
import androidx.annotation.RequiresApi
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material.Button
import androidx.compose.material.ButtonDefaults
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Text
import androidx.compose.material3.TextField
import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.scale
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.NavHostController
import androidx.navigation.compose.rememberNavController
import com.example.newproject_overseas.R
import com.example.newproject_overseas.ViewModel.OcrDetailViewModel
import com.example.newproject_overseas.components.TopApp
import com.maxkeppeker.sheets.core.models.base.rememberSheetState
import com.maxkeppeler.sheets.calendar.CalendarDialog
import com.maxkeppeler.sheets.calendar.models.CalendarConfig
import com.maxkeppeler.sheets.calendar.models.CalendarSelection

@RequiresApi(Build.VERSION_CODES.O)
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun OcrDetail(
    navController: NavHostController,
    ocrDetailVm: OcrDetailViewModel = viewModel(),
) {

    val calendarState = rememberSheetState()
    CalendarDialog(
        state = calendarState,
        config = CalendarConfig(
            monthSelection = true,
            yearSelection = true
        ),
        selection = CalendarSelection.Date{ date ->
            ocrDetailVm.birthday = date.toString()

    })

    var textValue by remember { mutableStateOf("") }
    Box(  modifier = Modifier
        .fillMaxSize()
        .background(color = Color(0XFFEFF0F3))){

        Column(
            modifier = Modifier
                .fillMaxSize()
                .background(color = Color(0XFFEFF0F3)),

            ) {

            TopApp(title = "OcrDetail", navController = navController)

            LazyColumn(
                modifier = Modifier
                    .padding(horizontal = 6.dp)
            ) {
                item {

                       Text(
                            text = "Idcard",
                            fontSize = 25.sp,
                            modifier = Modifier.padding(top = 20.dp, start = 10.dp)
                       )
                       TextField(
                            value = ocrDetailVm.idcard,
                            onValueChange = {
                                ocrDetailVm.idcard = it
                            },
                            colors = TextFieldDefaults.textFieldColors(
                                containerColor = Color.White, // White background
                                cursorColor = Color.Black,
                                textColor = Color.Black,
                                focusedIndicatorColor = Color.Transparent,
                                unfocusedIndicatorColor = Color.Transparent,
                            ),
                            shape = RoundedCornerShape(30.dp), // Rounded corners with a radius of 16dp
                            modifier = Modifier
                                .fillMaxWidth()
                                .height(70.dp)
                                .padding(8.dp)
                                .shadow(5.5.dp, shape = RoundedCornerShape(16.dp), clip = true)
                                .background(Color.White, RoundedCornerShape(16.dp)) // White background with rounded corners
                        )


                    Text(
                        text = "Realname",
                        fontSize = 25.sp,
                        modifier = Modifier.padding(top = 20.dp, start = 10.dp)
                    )
                    TextField(
                        value = ocrDetailVm.realname,
                        onValueChange = {
                            ocrDetailVm.realname = it
                        },
                        colors = TextFieldDefaults.textFieldColors(
                            containerColor = Color.White, // White background
                            cursorColor = Color.Black,
                            textColor = Color.Black,
                            focusedIndicatorColor = Color.Transparent,
                            unfocusedIndicatorColor = Color.Transparent,
                        ),
                        shape = RoundedCornerShape(16.dp), // Rounded corners with a radius of 16dp
                        modifier = Modifier
                            .fillMaxWidth()
                            .height(70.dp)
                            .padding(8.dp)
                            .shadow(5.5.dp, shape = RoundedCornerShape(16.dp), clip = true)
                            .background(Color.White, RoundedCornerShape(16.dp)) // White background with rounded corners
                    )


                    Text(
                        text = "Birthday",
                        fontSize = 25.sp,
                        modifier = Modifier.padding(top = 20.dp, start = 10.dp)
                    )

                    Row(
                        modifier = Modifier
                            .padding(top = 10.dp)
                            .padding(horizontal = 10.dp)
                            .clickable(onClick = { })
                            .shadow(5.dp, shape = RoundedCornerShape(16.dp), clip = true)
                            .background(
                                color = Color.White,
                                shape = RoundedCornerShape(16.dp)

                            ) // White background with rounded corners

                            .padding(8.dp)
                            .height(30.dp)
                            .fillMaxWidth()
                            .clickable {
                                print("点击")
                                calendarState.show()

                            },
                        verticalAlignment = Alignment.CenterVertically,
                    ) {
                        Text(text = ocrDetailVm.birthday)
                        Spacer(modifier = Modifier.weight(1f))
                        Image(
                            painter = painterResource(id = R.drawable.go_in),
                            contentDescription = null,
                            modifier = Modifier
                                .width(20.dp)
                                .height(20.dp)
                                .scale(0.9f)
                        )
                    }

                    Text(
                        text = "Taxregnumber",
                        fontSize = 25.sp,
                        modifier = Modifier.padding(top = 20.dp, start = 10.dp)
                    )
                    TextField(
                        value = ocrDetailVm.taxregnumber,
                        onValueChange = {
                            ocrDetailVm.taxregnumber = it
                        },
                        colors = TextFieldDefaults.textFieldColors(
                            containerColor = Color.White, // White background
                            cursorColor = Color.Black,
                            textColor = Color.Black,
                            focusedIndicatorColor = Color.Transparent,
                            unfocusedIndicatorColor = Color.Transparent,
                        ),
                        shape = RoundedCornerShape(16.dp), // Rounded corners with a radius of 16dp
                        modifier = Modifier
                            .fillMaxWidth()
                            .height(70.dp)
                            .padding(8.dp)
                            .shadow(5.5.dp, shape = RoundedCornerShape(16.dp), clip = true)
                            .background(Color.White, RoundedCornerShape(16.dp)) // White background with rounded corners
                    )

                }
            }
        }

        //底部按钮
        Button(onClick = { /*TODO*/ }, modifier = Modifier
            .fillMaxWidth(1f)
            .height(44.dp)
            .align(Alignment.BottomCenter),
            colors = ButtonDefaults.buttonColors(Color(0xFFFFCC00)),
            shape = RoundedCornerShape(4.5.dp)) {
            androidx.compose.material.Text(
                modifier = Modifier,
                text = "confirm",
                color = Color(0xFFFFFFFF),
                fontSize = 20.sp
            )
        }
    }
}




@Preview
@Composable
fun OcrDetailPreview() {
    val navController = rememberNavController() // 假设这里使用了导航控制器
    OcrDetail(navController)
}

